#include<iostream>
#include<vector>
using namespace std;
vector<int> vi, wi, si;
int n{0}, v{0}, tmp1{0}, tmp2{0}, tmp3{0};
int dp(int v, int i, bool tag);


int main()
{ 
    cin >> n >> v;
    for(int i = 0; i < n; i++)
    {
        cin >> tmp1 >> tmp2 >> tmp3;
        if(tmp3 == 0) tmp3 = -2;
        vi.push_back(tmp1);
        wi.push_back(tmp2);
        si.push_back(tmp3);
        cout << tmp3 << " ";
    }
    cout << endl;
    cout << dp(v, 0, false) << endl;
    return 0;
}

int dp(int v, int i, bool tag)  // 假设一开始不需要那么多的参数，后面再慢慢需要再加上去
{
    if(i >= n) return 0;
    if(tag) si[i]--;
    int value1{0}, value2{0};
    if(vi[i] <= v)
    {
        if(si[i] == -1)
        {
            value1 = wi[i] + dp(v-vi[i], i+1, false); 
            value2 = dp(v, i+1, false);
        }
        else if(si[i] == -2)
        {
            value1 = wi[i] + dp(v-vi[i], i, false); 
            value2 = dp(v, i+1, false);
        }
        else
        {
            if(si[i] >= 0) 
            {
                value1 = wi[i] + dp(v-vi[i], i, true); 
                value2 = dp(v, i+1, false);  
            }
            else
            {
                value1 = wi[i] + dp(v-vi[i], i+1, false); 
                value2 = dp(v, i+1, false);
            }
        }
    }
    tag = false;
    si[i]++;
    // cout << "value1: " << value1 << "  ";
    // cout << "value2: " << value2 << "  ";
    // cout << "volumn: " << v << "  ";
    // cout << "i: " << i << endl;
    if(value1 > value2) return value1;
    else return value2;
}